home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
xobbs.arc
/
xofiles.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-03
|
4KB
|
179 lines
/* XOFILES.C File handling routines for XOBBS. Jim Durham, W2XO 10-24-88 */
/* Version 1.0 */
/* Code released to the amateur radio community */
#include "xobbs.h"
/*PUTREC places a record in the file at location RECNUM. Location is determined
by multiplying the record size by the record number*/
putrec(fd,recnum,rec,size) /*put a record in the file at the given pos*/
int fd,recnum; /*agrs file descrip,rec number and pointer to*/
/*record*/
char *rec;
int size;
{
long offst;
offst=(long)recnum*(long)size;
lseek(fd,offst,0);
return(write(fd,rec,size));
}
/*GETREC gets a record from the file. It operation may be inferred by
studying PUTREC. GETREC reads the record into the address given
by the third argument, pointer REC*/
getrec(fd,recnum,rec,size) /*get a record from the file described by*/
int fd,recnum; /*fp and return error code*/
char *rec;
int size;
{
long offst;
offst=(long)recnum*(long)size;
lseek(fd,offst,0);
return(read(fd, rec, size));
}
upload(filnam)
char *filnam;
{
int fd,n,finish,i;
static char ch = '\n';
if((fd=open(lowcase(filnam),O_WRONLY|O_CREAT,0x1b6)) < 0)
{
sprintf(prinbuf,"Mailbox Cant Open %s\n",filnam);
prinout(NOFLUSH);
return(0);
}
sprintf(prinbuf,"Send the File %s , end upload with control-Z\n",filnam);
prinout(FLUSH);
for(;;){
getline(1);
n = strlen(inline);
finish = 0;
for(i=0;i < n; i++){
if(inline[i] == 26){
inline[i] = '\0';
n = strlen(inline);
finish = 1;
break;
}
}
if(inline[0] == '/') /* or, check for /EX */
if((inline[1] == 'E' || inline[1] == 'e')
&& (inline[2] == 'X' || inline[2] == 'x'))
finish = 1;
write(fd,inline,strlen(inline));
write(fd,&ch,1);
if(finish) break; /* ^Z or /EX was sent */
}
close(fd);
return(1);
}
download(filnam)
char *filnam;
{
int fd,bufcnt;
char c, *cp;
if((fd=open(lowcase(filnam),O_RDONLY)) < 1)
{
sprintf(prinbuf,"Can't locate %s\n",filnam);
prinout(NOFLUSH);
return(0);
}
bufcnt = 0;
cp=prinbuf;
while(c=xogetc(fd)){
if(c != '\n'){
*cp++ = c;
bufcnt++;
if(bufcnt > 254){ /*insert a newline if the user doesn't*/
*cp++ = '\n';
*cp = '\0';
prinout(NOFLUSH);
bufcnt = 0;
cp = prinbuf;
}
}
else{
*cp++ = c;
*cp = '\0';
prinout(NOFLUSH);
bufcnt = 0;
cp = prinbuf;
}
}
close(fd);
return(1);
}
/*make a file from a message*/
makefil()
{
int fd,fd2,fptr,i,found;
char hdr[128];
if(user.typ != 'S'){
sprintf(prinbuf,"Sorry, Sysops Only on this function\n");
prinout(NOFLUSH);
return;
}
if((fd2=openhdrfil()) < 0){
sprintf(prinbuf,"makefil: Can't open header file\n");
prinout(NOFLUSH);
perror("makfil:Opening Header:");
return;
}
fptr = 0;
found = 0;
while(read(fd2,hdr,89)){
fptr += 89;
if(!strncmp(hdr,command.fld[1],strlen(command.fld[1]))){
found = 1;
fptr -= 76;
lseek(fd2,0L,0); /* lock file*/
locking(fd2,1,0L);
lseek(fd2,(long)fptr,0); /*back to 'stat' byte in hdr*/
write(fd2,"X",1); /* write 'X' to it*/
lseek(fd2,0L,0); /* unlock file*/
locking(fd2,0,0L);
break; /* leave loop */
}
}
close(fd2);
if(found == 0){
sprintf(prinbuf,"Message File not found\n");
prinout(NOFLUSH);
return;
}
sprintf(prinbuf,"mv %s%s %s",maildir,command.fld[1],lowcase(command.fld[2]));
if(system(prinbuf)){
sprintf(prinbuf,"File Error");
prinout(NOFLUSH);
perror("makfil:System mv:");
return;
}
msgcnt--;
}